package learn.algorithm.utils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Random;

public class GeneralUtils {
    static Random random = new Random();

    public static int[] generateRandomArray(int n) {
        return generateRandomArray(n, 0, 100);
    }

    public static int[] generateRandomArray(int n, int min, int max) {
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = random.nextInt(max - min + 1) + min;
        }
        return arr;
    }

    public static int[] generateSortedArray(int n) {
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = i;
        }
        return arr;
    }

    public static void swap(int[] arr, int i, int j) {
        if (i > arr.length - 1 || j > arr.length - 1) {
            throw new RuntimeException("Index out of bounds, i = " + i
                    + ", j = " + j + ", arr.length = " + arr.length + ".");
        }
        if (i == j) {
            return;
        }
        int temp = arr[i];
        arr[i] = arr[j];
        arr[j] = temp;
    }

    public static void printArray(int[] arr) {
        for (int j : arr) {
            System.out.print(j + " ");
        }
        System.out.println();
    }
}
